import datetime
from re import findall


def strp_time(time: str):
    numbers = []
    try:
        hour = 0
        mi = 0
        se = 0
        numbers = findall('(\d+)', time)
        if len(numbers) >= 6:
            se = numbers[5]
        if len(numbers) >= 5:
            mi = numbers[4]
        if len(numbers) >= 4:
            hour = numbers[3]
        if len(numbers) >= 3:
            if '.' in time:
                year = numbers[2]
                month = numbers[1]
                day = numbers[0]
            else:
                day = numbers[2]
                month = numbers[1]
                year = numbers[0]
        try:
            return datetime.datetime(year=int(year), month=int(month), day=int(day), hour=int(hour), minute=int(mi),
                                     second=int(se))
        except Exception as e:
            return datetime.datetime(year=int(year), month=int(month), day=int(day))
    except Exception as e:
        try:
            special = False
            for i in numbers:
                if len(i) > 4:
                    special = True
                    break
            if special:
                day = 0
                for i in numbers:
                    if len(i) > 4:
                        y = i[0:4]
                        month = i[4:]
                        if len(month) > 2:
                            day = month[2:]
                            month = month[0:2]
                    else:
                        day = i
            else:
                if len(numbers) >= 3:
                    numbers = numbers[0:3]
                for i in range(0, len(numbers)):
                    if len(numbers[i]) == 4:
                        y = numbers[i]
                        del numbers[i]
                        break
                month = 0
                day = 0
                if len(numbers) >= 1:
                    if int(numbers[0]) > 12:
                        day = numbers[0]
                    else:
                        month = numbers[0]
                if len(numbers) >= 2:
                    if int(month) > 0:
                        day = numbers[1]
                    else:
                        month = numbers[1]
            try:
                if int(day) == 0:
                    return datetime.datetime(year=int(y), month=int(month), day=1)
                else:
                    return datetime.datetime(year=int(y), month=int(month), day=int(day))
            except Exception as e:
                tmp = month
                month = day
                day = tmp
                if int(month) <= 12:
                    return datetime.datetime(year=int(y), month=int(month), day=int(day))
        except Exception as e:
            print(time, str(e))
            return time

if __name__ == '__main__':
    print(strp_time("03.12.2022 16:22:11"))